package com.frank.controller;

import com.frank.dto.InterviewDto;
import com.frank.dto.InterviewUsersDto;
import com.frank.dto.JsonResult;
import com.frank.dto.QueryPageDto;
import com.frank.feign.RecruitFeign;
import com.frank.feign.ResumeFeign;
import com.frank.model.InterviewRecord;
import com.frank.model.Resume;
import com.frank.service.InterviewService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/interview")
public class InterviewController {

    @Resource
    private RecruitFeign recruitFeign;

    @Resource
    private ResumeFeign resumeFeign;

    @Resource
    private InterviewService interviewService;

    @RequestMapping(value = "/getInterviewList", method = RequestMethod.GET)
    public JsonResult<?> getInterviewList(@RequestBody QueryPageDto queryPageDto){
        List<InterviewDto> interviewDtoList = recruitFeign.getInterviewList(queryPageDto).getData();
        return new JsonResult<>(200,"获取面试场次列表成功",interviewDtoList);
    }

    @RequestMapping(value = "/getUsersByInterviewId", method = RequestMethod.GET)
    public JsonResult<?> getUsersByInterviewId(@RequestParam("interviewId") Integer interviewId) {
        List<InterviewUsersDto> interviewUsersDtoList = interviewService.getUsersByInterviewId(interviewId);
        return new JsonResult<>(200,"获取参与面试用户们成功",interviewUsersDtoList);
    }

    @RequestMapping(value = "/attachInterview", method = RequestMethod.POST)
    public JsonResult<?> attachInterview(@RequestParam("interviewRecordId") Integer interviewRecordId) {
        interviewService.attachInterview(interviewRecordId);
        return new JsonResult<>(200,"面试签到成功");
    }

    @RequestMapping(value = "/unAttachInterview", method = RequestMethod.POST)
    public JsonResult<?> unAttachInterview(@RequestParam("interviewRecordId") Integer interviewRecordId) {
        interviewService.unAttachInterview(interviewRecordId);
        return new JsonResult<>(200,"面试未到操作成功");
    }

    @RequestMapping(value = "/getResumeByUserId", method = RequestMethod.GET)
    public JsonResult<?> getResumeByUserId(@RequestParam("userId") Integer userId){
        Resume resume = resumeFeign.getResumeByUserId(userId).getData();
        return new JsonResult<>(200,"获取面试场次列表成功",resume);
    }

    @RequestMapping(value = "/finishInterview", method = RequestMethod.POST)
    public JsonResult<?> finishInterview(@RequestBody InterviewRecord interviewRecord) {
        boolean result = interviewService.finishInterview(interviewRecord);
        if (result){
            return new JsonResult<>(200,"完成面试成功");
        }else {
            return new JsonResult<>(500,"完成面试失败");
        }
    }

}
